package com.example.a2205_fx.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a2205_fx.R;
import com.example.a2205_fx.adapter.VideoMineAdapter;
import com.example.a2205_fx.base.BaseViewActivity;
import com.example.a2205_fx.base.BaseViewFragment;
import com.example.a2205_fx.database.AppDataBaseUtil;
import com.example.a2205_fx.databinding.FragmentMineBinding;
import com.example.a2205_fx.entity.VideoEntity;

import java.util.ArrayList;
import java.util.List;


public class MineFragment extends BaseViewFragment<FragmentMineBinding> {

    List<VideoEntity.DataBean> videos = new ArrayList<>();
    VideoMineAdapter videoMineAdapter;



    public MineFragment() {
        // Required empty public constructor
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

        videoMineAdapter = new VideoMineAdapter(R.layout.item_video,videos);
        binding.rv.setAdapter(videoMineAdapter);
        binding.rv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));

        List<VideoEntity.DataBean> query = AppDataBaseUtil.getInstance().getVideoDao().query();
        videos.clear();
        videos.addAll(query);
        videoMineAdapter.notifyDataSetChanged();



    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_mine;
    }

    @Override
    public void onResume() {
        super.onResume();
        List<VideoEntity.DataBean> query = AppDataBaseUtil.getInstance().getVideoDao().query();
        videos.clear();
        videos.addAll(query);
        videoMineAdapter.notifyDataSetChanged();
    }
}